package argo.hot100.tree;

import java.util.Stack;

public class IsValidBST {

    public boolean isValidBST(TreeNode root) {

        Stack<TreeNode> stack = new Stack<>();
        Double preVal =-Double.MAX_VALUE;

        while (!stack.isEmpty() || root != null) {
            while (root != null) {
                stack.push(root);
                root = root.left;
            }
            root = stack.pop();
            if (root.val <= preVal) {
                return false;
            }
            preVal =Double.valueOf( root.val);
            root = root.right;

        }

        return true;
    }
}
